#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""  
@Project : pythonProject01
@File : portscan_val.py
@Author : erhu
@Time : 2025/9/10 11:01  
@脚本说明 : 
"""
import socket
import threading
def scan_port(host, port_start, sep=10):
    # 构造分段 扫描
    for port in range(port_start, port_start + sep):
        try:
            tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            tcp.settimeout(0.1)
            result = tcp.connect_ex((host, port))
            if result == 0:
                print(f"[+] {host}:{port} 端口开启")
            tcp.close()
        except:
            pass
def scan_port_run(host, sep):
    threads = []
    print("======全端口扫描======")
    for i in range(0, 65535, sep):
        t = threading.Thread(target=scan_port, args=(host, i, sep))
        t.start()
        threads.append(t)
    for t in threads:
        t.join()
    print("\n扫描结束")